package com.howcan.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnLongClickListener;
import android.widget.Adapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import java.util.LinkedList;

import com.howcan.v1.R;

public class LiteListView extends LinearLayout
  implements View.OnFocusChangeListener, View.OnClickListener, View.OnLongClickListener
{
  private static final Object DIVIDER_TAG = new Object();
  private Adapter adapter;
  public boolean alwaysShowDivider;

  private Handler handler = new Handler()
  {
    public void handleMessage(Message paramMessage)
    {

/*      while (true)
      {
        LiteListView.this.addView(localView3);
        k = i2;
        ++l;
        break label151:
        label344: View localView1 = LiteListView.this.getChildAt(i);
        if (localView1.getTag() == LiteListView.DIVIDER_TAG)
          localLinkedList2.addLast(localView1);
        while (true)
        {
          ++i;
          break label92:
          localLinkedList1.addLast(localView1);
        }
        label387: localBaseAdapter = null;
        break label131:
        i2 = 1;
        break label176:
        label399: localView4 = (View)localLinkedList2.removeFirst();
        break label217:
        label411: localView2 = (View)localLinkedList1.removeFirst();
        break label236:
        label423: localView3.setOnLongClickListener(LiteListView.this);
        continue;
        label435: localView3.setOnFocusChangeListener(null);
        localView3.setOnClickListener(null);
        localView3.setOnLongClickListener(null);
        localView3.setSelected(false);
        localView3.setFocusable(false);
        localView3.setClickable(false);
        LiteListView.this.setBackground(localView3, false);
        localView3.setLongClickable(false);
      }
*/ 
      }
  };

  
  private LayoutInflater inflater;
 
  private final DataSetObserver observer = new DataSetObserver()
  {
    public void onChanged()
    {
      LiteListView.this.handler.removeMessages(1);
      LiteListView.this.handler.sendEmptyMessageDelayed(1, 100L);
    }

    public void onInvalidated()
    {
      onChanged();
    }
  };

  
  private AdapterView.OnItemClickListener onClickListener;
  private AdapterView.OnItemLongClickListener onLongClickListener;

  public LiteListView(Context paramContext)
  {
    this(paramContext, null);
  }

  public LiteListView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    TypedArray localTypedArray = paramContext.obtainStyledAttributes(paramAttributeSet, R.styleable.LiteListView);
    this.alwaysShowDivider = localTypedArray.getBoolean(0, false);
    localTypedArray.recycle();
    this.inflater = LayoutInflater.from(paramContext);
    setOrientation(1);
  }

  public Adapter getAdapter()
  {
    return this.adapter;
  }

  protected View getDivider()
  {
    View localView = this.inflater.inflate(R.layout.list_divider, this, false);
    localView.setTag(DIVIDER_TAG);
    return localView;
  }

  public void onFocusChange(View paramView, boolean paramBoolean)
  {
    paramView.setSelected(paramBoolean);
  }

  public void setAdapter(Adapter paramAdapter)
  {
    if (this.adapter != null)
      this.adapter.unregisterDataSetObserver(this.observer);
    this.adapter = paramAdapter;
    if (this.adapter != null)
      this.adapter.registerDataSetObserver(this.observer);
    removeAllViews();
    this.observer.onChanged();
  }

  public void setOnItemClickListener(AdapterView.OnItemClickListener paramOnItemClickListener)
  {
    this.onClickListener = paramOnItemClickListener;
    this.handler.sendEmptyMessage(1);
  }

  public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener paramOnItemLongClickListener)
  {
    this.onLongClickListener = paramOnItemLongClickListener;
    this.handler.sendEmptyMessage(1);
  }

public void onClick(View v) {
	// TODO Auto-generated method stub
	
}

public boolean onLongClick(View v) {
	// TODO Auto-generated method stub
	return false;
}
}
